package org.dromara.system.controller.device;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.pojo.*;
import org.dromara.system.domain.vo.DashVo;
import org.dromara.system.domain.vo.DeviceAlarmVo;
import org.dromara.system.domain.vo.DeviceGroupVo;
import org.dromara.system.service.IDeviceService;
import org.dromara.system.service.ISysLogininforService;
import org.dromara.system.service.ISysSystemReportService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备报警
 *
 * @author Lion Li
 * @date 2024-10-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/home")
public class HomeScreenController extends BaseController {

    private final IDeviceService deviceService;
    private final ISysSystemReportService sysSystemReportService;

    private final ISysLogininforService loginService;

    @SaCheckPermission("system:device:list")
    @GetMapping("/deviceOverview")
    @Log(title = "设备概述", businessType = BusinessType.OTHER)
    public R<List<DeviceOverview>> deviceOverview() {
        return R.ok(deviceService.deviceOverview());
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/liquidLevelGauge")
    @Log(title = "液位仪", businessType = BusinessType.OTHER)
    public R<List<DeviceGroupVo>> liquidLevelGauge() {
        return R.ok(deviceService.liquidLevelGauge());
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/deviceNum")
    @Log(title = "设备数量", businessType = BusinessType.OTHER)
    public R<DashVo> deviceNum() {
        return R.ok(deviceService.dashBroad());
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/deviceStatistics/{tunnelId}")
    @Log(title = "设备统计", businessType = BusinessType.OTHER)
    public R<List<DeviceStatisticsByScreenVo>> deviceStatistics(@PathVariable("tunnelId") Long tunnelId) {
        return R.ok(sysSystemReportService.deviceStatistics(tunnelId));
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/paramStatistics")
    @Log(title = "参数统计", businessType = BusinessType.OTHER)
    public R<VariableData> paramStatistics() {
        return R.ok(sysSystemReportService.paramStatistics());
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/paramTotalStatistics")
    @Log(title = "参数采集总量统计", businessType = BusinessType.OTHER)
    public R<List<ParamTotalStatistics>> paramTotalStatistics() {
        return R.ok(sysSystemReportService.paramTotalStatistics());
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/todayAlarm")
    @Log(title = "今日报警", businessType = BusinessType.OTHER)
    public R<List<ParamTotalStatistics>> todayAlarm() {
        return R.ok(sysSystemReportService.todayAlarm());
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/alarmStatistics")
    @Log(title = "报警统计", businessType = BusinessType.OTHER)
    public R<WeekData> alarmStatistics() {
        return R.ok(sysSystemReportService.alarmStatistics());
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/alarmTopThreeGroup")
    @Log(title = "报警top3分组统计", businessType = BusinessType.OTHER)
    public R<List<ParamTotalStatistics>> alarmTopThreeGroup() {
        return R.ok(sysSystemReportService.sysSystemReportService());
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/loginRecord")
    @Log(title = "登录记录", businessType = BusinessType.OTHER)
    public R<List<LoginLogVo>> alarmProcessingRecord() {
        return R.ok(loginService.alarmProcessingRecord());
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/importantDevice")
    @Log(title = "重点设备", businessType = BusinessType.OTHER)
    public R<List<TunnelStats>> importantDevice() {
        return R.ok(sysSystemReportService.importantDevice());
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/maintenancePlan")
    @Log(title = "管养计划", businessType = BusinessType.OTHER)
    public R<NoticeVo> maintenancePlan() {
        return R.ok(sysSystemReportService.maintenancePlan());
    }

    @SaCheckPermission("system:device:list")
    @PostMapping("/maintenancePlan")
    @Log(title = "管养计划", businessType = BusinessType.OTHER)
    public R maintenancePlan(@RequestBody NoticeVo noticeVo) {
        sysSystemReportService.setMaintenancePlan(noticeVo);
        return R.ok();
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/alarmLatest")
    @Log(title = "最新报警", businessType = BusinessType.OTHER)
    public R<DeviceAlarmVo> alarmLatest() {
        return R.ok(sysSystemReportService.alarmLatest());
    }


}
